<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CatalogModel
 *
 * @author Administrator
 */
Import('@.Unit.Common');

class CatalogModel extends BaseModel {

    //put your code here
    //获取我所有群组  加入审核通过的群组
    function addcata($catalog_name, $group_ids, $catalog_id = 0) {
        $catalog_id = intval($catalog_id);
        $catalog['catalog_name'] = trim($catalog_name);
        $catalog['group_ids'] = trim($group_ids);
        if ($catalog_id == 0) {
            return D('Catalog')->add($catalog);
        }
        $catalog['catalog_id'] = $catalog_id;
        return D('Catalog')->save($catalog);
    }

    function getAllCatalog($group_id) {
        $in = 'group_ids=\'all\'';
        if ($group_id) {
            $in = 'group_ids=\'all\' or group_ids like \'%,' . $group_id . ',%\'';
        }
        $groupList = D('Catalog')->where($in)->findAll();
        return $groupList;
    }

    function delcata($catalog_id) {
        $in = array('catalog_id' => $catalog_id);
        $groupList = D('Catalog')->where($in)->delete();
        return $groupList;
    }

    function getdata($catalog_id) {
        $in = array('catalog_id' => $catalog_id);
        $groupList = D('Catalog')->where($in)->find();
        return $groupList;
    }

    function getAllCatalogs() {
        $groupList = D('Catalog')->findAll();
        return $groupList;
    }

}
